<template>
  <div class="box">
    <div class="f1">
      <ul>
        <li>
          <div class="icon">
            <img class="icon1" src="@/assets/PC/金融服务/组30.png" alt="" />
            <img class="icon2" src="../../assets/PC/金融服务/组31.png" alt="" />
          </div>
          <span style="margin-left: -4px">企业认证</span>
        </li>
        <li>
          <div class="icon">
            <img class="icon1" src="@/assets/PC/金融服务/组32.png" alt="" />
            <img class="icon2" src="../../assets/PC/金融服务/组31.png" alt="" />
          </div>
          <span>填写申请信息</span>
        </li>
        <li>
          <div class="icon">
            <img class="icon1" src="@/assets/PC/金融服务/组34.png" alt="" />
          </div>
          <span>业务提交完成</span>
        </li>
      </ul>
    </div>
    <!-- <h3 class="unit">单位：元</h3> -->
    <div class="f2">
      <ul class="ul">
        <li>
          <el-form ref="forms" :model="form" label-width="220px" :rules="rules">
            <el-form-item label="企业纳税信用等级">
              <el-select v-model="form.a" placeholder="请选择">
                <el-option key="14" label="请选择" value=""></el-option>
                <el-option key="1" label="A" value="A"></el-option>
                <el-option key="2" label="B" value="B"></el-option>
                <el-option key="3" label="C" value="C"></el-option>
                <el-option key="4" label="D" value="D"></el-option>
                <el-option key="5" label="M" value="M"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
          <el-form ref="forms" :model="form" label-width="320px" :rules="rules">
            <el-form-item label="企业法定代表人是否存在严重违法记录">
              <el-select v-model="form.b" placeholder="请选择">
                <el-option key="14" label="请选择" value=""></el-option>
                <el-option key="1" label="是" value="1"></el-option>
                <el-option key="2" label="否" value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </li>
        <li>
          <el-form ref="forms" :model="form" label-width="220px" :rules="rules">
            <el-form-item label="企业未结清融资机构数量">
              <el-input v-model="form.c" @blur="c()" placeholder=""></el-input>
              <p class="message" v-show="c1">格式错误，请重新输入</p>
            </el-form-item>
          </el-form>
          <el-form ref="forms" :model="form" label-width="320px" :rules="rules">
            <el-form-item label="企业法定代表人是否存在行政处罚记录">
              <el-select v-model="form.d" placeholder="请选择">
                <el-option key="14" label="请选择" value=""></el-option>
                <el-option key="1" label="是" value="1"></el-option>
                <el-option key="2" label="否" value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </li>
        <li style="position: relative">
          <el-form :model="form" label-width="220px" :rules="rules">
            <el-form-item label="企业未结清融资金额">
              <el-input
                @blur="costChangeE"
                @focus="
                  () => {
                    this.form.e = remoney(this.form.e);
                  }
                "
                @input="limitInput($event, 'e')"
                v-model="form.e"
                placeholder=""
              ></el-input>
              <!-- <p
                style="
                  width: 100%;
                  color: #999;
                  position: absolute;
                  left: -181px;
                  top: 10px;
                  font-size: 13px;
                "
              >
                含对外担保、他行融资、贴现
              </p> -->
              <p
                style="
                  position: absolute;
                  right: 15px;
                  top: 0px;
                  z-index: 999;
                  font-size: 16px;
                "
              >
                元
              </p>
            </el-form-item>
          </el-form>
          <el-form ref="forms" :model="form" label-width="320px" :rules="rules">
            <el-form-item label="企业法定代表人是否存在征信不良信用记录">
              <el-select v-model="form.f" placeholder="请选择">
                <el-option key="14" label="请选择" value=""></el-option>
                <el-option key="1" label="是" value="1"></el-option>
                <el-option key="2" label="否" value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </li>
        <li style="position: relative">
          <el-form ref="forms" :model="form" label-width="220px" :rules="rules">
            <el-form-item label="企业当前是否存在逾期">
              <el-select v-model="form.g" placeholder="请选择">
                <el-option key="14" label="请选择" value=""></el-option>
                <el-option key="1" label="是" value="1"></el-option>
                <el-option key="2" label="否" value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
          <el-form ref="forms" :model="form" label-width="320px" :rules="rules">
            <el-form-item label="企业法定代表人未结清经营贷款余额">
              <el-input
                @blur="costChangeH"
                @focus="
                  () => {
                    this.form.h = remoney(this.form.h);
                  }
                "
                @input="limitInput($event, 'h')"
                v-model="form.h"
                placeholder=""
              ></el-input>
              <p
                style="
                  position: absolute;
                  right: 15px;
                  top: 0px;
                  z-index: 999;
                  font-size: 16px;
                "
              >
                元
              </p>
            </el-form-item>
          </el-form>
        </li>
        <li>
          <el-form ref="forms" :model="form" label-width="220px" :rules="rules">
            <el-form-item label="企业是否存在征信不良信用记录">
              <el-select v-model="form.j" placeholder="请选择">
                <el-option key="14" label="请选择" value=""></el-option>
                <el-option key="1" label="是" value="1"></el-option>
                <el-option key="2" label="否" value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
          <el-form ref="forms" :model="form" label-width="320px" :rules="rules">
            <el-form-item label="可接受融资成本">
              <el-input
                @blur="costChangeI"
                @focus="
                  () => {
                    this.form.i = remoney(this.form.i);
                  }
                "
                @input="limitInput($event, 'i')"
                v-model="form.i"
                placeholder=""
              ></el-input>
              <p style="width: 10px; position: absolute; top: 0px; right: 18px">
                %
              </p>
            </el-form-item>
          </el-form>
        </li>
      </ul>
      <!-- 上一步/保存/提交 按钮 -->
      <div class="submit">
        <button :disabled="isLock" class="btn btn3" @click="goNextFlow()">
          下一步
        </button>
      </div>
    </div>
    <!-- <div class="f3" @click="goNextFlow()">下一步</div> -->
  </div>
</template>

<script>
import {
  selectallSP,
  findaddbusapplys,
  BusinessSpProductapplys0,
} from "@/utils";

export default {
  data() {
    return {
      radio: "",
      isLock: false,
      procedureId: "", // 产品ID状态变量
      productcode: "", //产品编号
      productname: "", //产品名称
      show01: "", //产品名称码值
      ProductList: null,
      index: "",
      c1: false,
      form: {
        a: "",
        b: "",
        c: "",
        d: "",
        e: "",
        f: "",
        g: "",
        h: "",
        i: "",
        j: "",
        applyId: "",
        spid: "",
      },
      // 用户填写资料表格
      addform: {
        a: "",
        b: "",
        c: "",
        d: "",
        e: "",
        f: "",
        g: "",
        h: "",
        i: "",
        j: "",
      },
      // 表单验证
      rules: {
        a: [{ required: true, message: " ", trigger: "blur" }],
        b: [{ required: true, message: " ", trigger: "blur" }],
        c: [{ required: true, message: " ", trigger: "blur" }],
        d: [{ required: true, message: " ", trigger: "blur" }],
        e: [{ required: true, message: " ", trigger: "blur" }],
        f: [{ required: true, message: " ", trigger: "blur" }],
        g: [{ required: true, message: " ", trigger: "blur" }],
        h: [{ required: true, message: " ", trigger: "blur" }],
        i: [{ required: true, message: " ", trigger: "blur" }],
        j: [{ required: true, message: " ", trigger: "blur" }],
      },
    };
  },
  // 生命周期方法
  mounted() {
    this.BusinessSpProductapplys0();
    this.selectallSP();
  },
  methods: {
    // 调用产品申请第0步接口
    async BusinessSpProductapplys0() {
      let { data } = await BusinessSpProductapplys0(this.procedureId);
      if (data == 0) {
        this.form.applyId = 0;
      }
      if (data != 0) {
        let info = data.businessSPinfo;
        this.form.a = info.enterprise;
        this.form.b = info.outrage;
        this.form.c = info.outstanding;
        this.form.d = info.punishment;
        // this.addform.e = info.entoutstanding;
        this.form.f = info.defaulter;
        this.form.g = info.entoverdue;
        // this.addform.h = info.operating;
        // this.addform.i = info.financing;
        this.form.j = info.entrecords;
        this.form.applyId = info.applyid;
        this.form.spid = info.spid;
        // 企业未结清金额
        if (
          parseInt(Number(info.entoutstanding), 10) !=
          Number(info.entoutstanding)
        ) {
          this.form.e = Number(info.entoutstanding).toLocaleString();
        } else {
          this.form.e = Number(info.entoutstanding).toLocaleString() + ".00";
        }
        // 企业法定代表人未结清经营贷款余额
        if (parseInt(Number(info.operating), 10) != Number(info.operating)) {
          this.form.h = Number(info.operating).toLocaleString();
        } else {
          this.form.h = Number(info.operating).toLocaleString() + ".00";
        }
        // 可接受融资成本;
        if (parseInt(Number(info.financing), 10) != Number(info.financing)) {
          this.form.i = Number(info.financing).toLocaleString();
        } else {
          this.form.i = Number(info.financing).toLocaleString() + ".00";
        }
        this.addform.e = info.entoutstanding;
        this.addform.h = info.operating;
        this.addform.i = info.financing;

        return;
      }
    },
    // 获取商票译产品列表
    async selectallSP() {
      let { data } = await selectallSP();
      this.ProductList = data[this.index];
    },
    // 前往下一个流程， 调用产品申请1接口将客户填写的数据返回至后端
    async goNextFlow() {
      this.isLock = true;
      setTimeout(() => {
        this.isLock = false;
      }, 3000);
      let { a, b, c, d, f, g, j } = this.form;
      let { e, h, i } = this.addform;
      h = h.toString();
      e = c.toString();
      i = i.toString();
      c = i.toString();
      let datas = {
        producttype: this.show01,
        enterprise: this.form.a,
        outrage: this.form.b,
        outstanding: this.form.c,
        punishment: this.form.d,
        entoutstanding: this.addform.e + "",
        defaulter: this.form.f,
        entoverdue: this.form.g,
        operating: this.addform.h + "",
        financing: this.addform.i + "",
        entrecords: this.form.j,
        productcood: this.productcode,
        productname: this.productname,
        productid: this.procedureId,
        applyId: this.form.applyId,
        spid: this.form.spid,
      };
      let { data } = await findaddbusapplys(datas);
      if (data) {
        if (this.show01 == "90" || this.show01 == "92" || this.show01 == "93") {
          localStorage.setItem("applyid", applyid);
          localStorage.setItem("productcode", this.productcode);
          localStorage.setItem("show01", this.show01);
          localStorage.setItem("radio", this.radio);
          // 跳贴现申请
          this.$router.push(`/enquiryApply2`);
        } else if (this.show01 == "91") {
          localStorage.setItem("applyid", data.applyid);
          localStorage.setItem("productcode", this.productcode);
          localStorage.setItem("show01", this.show01);
          localStorage.setItem("radio", this.radio);
          // 跳质押申请
          this.$router.push(`/enquiryPledgeApply`);
        }
      }
      return;
    },
    // 表单数据
    c() {
      this.c1 = false;
      if (this.form.c == "") return;
      this.form.c = parseInt(this.form.c);
      if (isNaN(this.form.c)) {
        this.form.c = "";
        this.c1 = true;
      }
    },
    // 表单格式转换

    costChangeE(e) {
      let a = Number(e.target.value);
      a = a.toFixed(2);
      if (a == "NaN") return (this.form.e = "");
      this.addform.e = this.form.e;
      //获取输入的数据，若不写这行，数据可能输不进去
      this.form.e = e.target.value;
      //将用户输入的数据，自动转换为带千分符的
      this.form.e = this.fmoney(this.form.e);
    },

    costChangeH(e) {
      let a = Number(e.target.value);
      a = a.toFixed(2);
      if (a == "NaN") return (this.form.h = "");
      this.addform.h = this.form.h;
      //获取输入的数据，若不写这行，数据可能输不进去
      this.form.h = e.target.value;
      //将用户输入的数据，自动转换为带千分符的
      this.form.h = this.fmoney(this.form.h);
    },
    costChangeI(e) {
      let a = Number(e.target.value);
      a = a.toFixed(2);
      if (a == "NaN") return (this.form.i = "");
      this.addform.i = this.form.i;
      //获取输入的数据，若不写这行，数据可能输不进去
      this.form.i = e.target.value;
      //将用户输入的数据，自动转换为带千分符的
      this.form.i = this.fmoney(this.form.i);
    },
    // 票面金额
    limitInput(value, name) {
      this.addform[name] =
        ("" + value) // 第一步：转成字符串
          .replace(/[^\d^\.]+/g, "") // 第二步：把不是数字，不是小数点的过滤掉
          .replace(/^0+(\d)/, "$1") // 第三步：第一位0开头，0后面为数字，则过滤掉，取后面的数字
          .replace(/^\./, "0.") // 第四步：如果输入的第一位为小数点，则替换成 0. 实现自动补全
          .match(/^\d*(\.?\d{0,2})/g)[0] || "";
    },
    //千分位格式化：10000转为10,000.00
    fmoney(s, n) {
      if (s == "" || s == null || (s == undefined) | isNaN(Number(s))) {
        return s;
      }
      s = Number(s) ? Number(s) : s;
      n = (n || n == 0) && n > -1 && n <= 20 ? n : 2;
      s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
      var l = s.split(".")[0].split("").reverse();
      var r = s.split(".")[1];
      var t = "";
      for (var i = 0; i < l.length; i++) {
        t += l[i] + ((i + 1) % 3 == 0 && i + 1 != l.length ? "," : "");
      }
      if (n > 0) {
        r = "." + r;
      } else if (n == 0) {
        r = "";
      }
      let returnT = t.split("").reverse().join("") + r;
      //负数处理
      if (returnT[0] == "-" && returnT[1] == ",") {
        returnT = "-" + returnT.substring(2);
      }
      return returnT;
    },
    //千分位反格式化:10,000.00转为10000.00
    remoney(s) {
      let str = "";
      if (s) {
        str = String(s).replace(/,/g, "");
      }
      if (s && (s + "").indexOf(".") > -1 && Number(str)) {
        return String(s).replace(/[^\d\.-]/g, "");
      } else if (s && Number(str)) {
        return str;
      } else {
        return s;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.box {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
  .f1 {
    margin-top: 20px;
    ul {
      display: flex;
      align-items: center;
      li {
        display: flex;
        flex-direction: column;
        height: 40px;
        .icon {
          .icon1 {
            width: 40px;
          }
          .icon2 {
            width: 250px;
            height: 3px;
            margin: 0 8px;
          }
        }
        span {
          font-size: 14px;
          font-family: Source Han Sans SC;
          font-weight: 400;
          color: #999999;
          margin-left: -19px;
          margin-top: 3px;
        }
      }
    }
  }
  .unit {
    z-index: 999;
    position: relative;
    @media only screen and (min-width: 1580px) and (max-width: 1950px) {
      left: 537px;
      top: 75px;
    }
    left: 537px;
    top: 55px;
    font-size: 16px;
    font-family: Source Han Sans SC;
    font-weight: 400;
    color: #b3b3b3;
    font-size: 14px;
    color: #606266;
  }
  .f2 {
    margin-top: 5%;
    width: 100%;
    ul {
      li {
        position: relative;
        width: 100%;
        margin-bottom: 18px;
        height: 50px;
        display: flex;
        justify-content: center;
        .message {
          position: absolute;
          top: 35px;
          font-size: 12px;
          font-family: Source Han Sans SC;
          font-weight: 300;
          color: #ef2d46;
        }
      }
    }
  }
  .submit {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 50px;
    margin: 5px 0 5px 0;
    cursor: pointer;
    .btn {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 180px;
      height: 34px;
      background: #0a7be0;
      border-radius: 4px;
      font-size: 16px;
      font-family: Source Han Sans SC;
      font-weight: 300;
      color: #ffffff;
      margin-right: 30px;
    }
  }
}
/* 输入框样式  */
::v-deep(.el-input__inner) {
  box-sizing: border-box;
  width: 250px !important;
  height: 39px;
  font-size: 15px;
  border: 1px solid #e0e0e0;
  border-radius: 0px;
  padding: 10px 10px;
  color: #606266;
  outline: 0;
  line-height: 35px !important;
}
</style>
<style lang="scss"></style>
